package com.six.firstpage.controller.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.six.core.entity.ZoneGoods;
import com.six.core.vo.GoodsVo;
import com.six.core.vo.Result;
import com.six.firstpage.feign.GoodsFeign;
import com.six.firstpage.service.ZoneGoodsService;
import com.six.firstpage.service.impl.ZoneGoodsServiceImpl;
import com.six.firstpage.vo.ZoneGoodsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.message.ReusableMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:zzh
 * @create: 2023-03-02 11:55
 * @Description:
 */
@Api(value = "/firstpage/api/zoneGoods", tags = {"专区管理前端Api"})
@RestController
@RequestMapping("/firstpage/api/zoneGoods")
//@CrossOrigin
public class ApiZoneGoodsController {
    @Autowired
    private ZoneGoodsServiceImpl service;

    @Autowired
    private GoodsFeign goodsFeign;

    //查询所有的商品
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "GoodsVo", name = "goodsVo", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "pageSize", value = "", required = true)
    })
    @ApiOperation(value = "查询所有的商品", notes = "查询所有的商品", httpMethod = "POST")
    @PostMapping("zoneGetGoods/{currentPage}/{pageSize}")
    public Result zoneGetGoods(@RequestBody GoodsVo goodsVo,@PathVariable Integer currentPage,@PathVariable Integer pageSize){
        return service.getZoneGoods(currentPage,pageSize,goodsVo);
    }


    //查询
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ZoneGoodsVo", name = "vo", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "current", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "pageSize", value = "", required = true)
    })
    @ApiOperation(value = "查询", notes = "查询", httpMethod = "POST")
    @PostMapping("getZoneGoods/{current}/{pageSize}")
    public Result getZoneGoods(@RequestBody ZoneGoodsVo vo,@PathVariable Integer current, @PathVariable Integer pageSize){
        IPage<ZoneGoodsVo> zoneGoodsById = service.getZoneGoodsById(vo, current, pageSize);
        return new Result(2000,"查询专区商品成功",zoneGoodsById);
    }

    //添加
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ZoneGoods", name = "zoneGoods", value = "", required = true)
    })
    @ApiOperation(value = "添加", notes = "添加", httpMethod = "POST")
    @PostMapping("addZoneGoods")
    public Result addZoneGoods(@RequestBody ZoneGoods zoneGoods){
        Integer integer = service.addZonGoods(zoneGoods);
        if (integer>0){
            return new Result(2000,"添加专区商品成功");
        }
        return new Result(5000,"添加专区商品失败");
    }

    //修改状态
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ZoneGoods", name = "zoneGoods", value = "", required = true)
    })
    @ApiOperation(value = "修改状态", notes = "修改状态", httpMethod = "PUT")
    @PutMapping("updateZoneGoods")
    public Result updateZoneGoods(@RequestBody ZoneGoods zoneGoods){
        Integer integer = service.updateZoneGoods(zoneGoods);
        if (integer>0){
            return new Result(2000,"修改专区商品状态成功");
        }
        return new Result(5000,"修改专区商品状态失败");
    }


    //逻辑删除
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "逻辑删除", notes = "逻辑删除", httpMethod = "GET")
    @GetMapping("delZoneGoods/{id}")
    public Result delZoneGoods(@PathVariable Integer id){
        Integer integer = service.delZoneGoods(id);
        if (integer>0){
            return new Result(2000,"删除专区商品成功");
        }
        return new Result(5000,"删除专区商品失败");
    }


}
